//
//  CommentSuccessViewController.m
//  LvXi_newVersion
//
//  Created by 王敏 on 16/9/5.
//  Copyright © 2016年 SJT. All rights reserved.
//

#import "CommentSuccessViewController.h"

#import "CommentSuccessHeader.h"

#import "CommentSuccessCell.h"

@interface CommentSuccessViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>


@property(nonatomic,strong)UICollectionView * collectionView;

@end

@implementation CommentSuccessViewController
-(id)iniWithCommentSuccessViewControllerStyle:(CommentSuccessViewControllerStyle)style{
    if(self == [super init]){
        self.style = style;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.collectionView];
}

-(UICollectionView*)collectionView{
    if(_collectionView == nil){
        UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init];
        layout.minimumLineSpacing = globalMargin;
        layout.sectionInset = UIEdgeInsetsMake(globalMargin, globalMargin, 0, globalMargin);
        CGFloat itemWidth = (ScreenWidth - 3*globalMargin)/2;
        layout.itemSize =CGSizeMake(itemWidth, itemWidth*1.3);
        layout.headerReferenceSize = CGSizeMake(ScreenWidth, 170);
        
        _collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
        _collectionView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = HexColor(@"#EEEEEE");
        
        [_collectionView registerClass:[CommentSuccessCell class] forCellWithReuseIdentifier:@"CommentSuccessCell"];
        [_collectionView registerClass:[CommentSuccessHeader class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CommentSuccessHeader"];
    }
    return _collectionView;
}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 10;
}

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    CommentSuccessCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CommentSuccessCell" forIndexPath:indexPath];
    cell.price = [NSString stringWithFormat:@"%.2f",(arc4random()%100)/9.0];
    return cell;
}

-(UICollectionReusableView*)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if(kind == UICollectionElementKindSectionHeader){
        CommentSuccessHeader * header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CommentSuccessHeader" forIndexPath:indexPath];
        header.style = self.style;
        return header;
    }
    return nil;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    switch (self.style) {
        case CommentSuccessViewControllerStyleComOrder:
        case CommentSuccessViewControllerStyleComSuccess:{
            return CGSizeMake(ScreenWidth, 170);
        } break;
        case CommentSuccessViewControllerStyleRecGoods:{
            return CGSizeMake(ScreenWidth, 210);
        } break;
        default:return CGSizeZero;break;
    }
    return CGSizeZero;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setUpNavi];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}

-(void)setUpNavi{
    [super setUpNavi];
    self.navigationItem.title = @"评价成功";
}

@end
